//
//  JSViewController49.swift
//  RXSwiftTest
//
//  Created by ZhangBo on 2019/6/19.
//  Copyright © 2019 ZhangBo. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa
import Moya
import SwiftyJSON
import Result



class JSViewController49: BaseViewController {
    let disposeBag = DisposeBag()
    //频道列表数据
    var channels: Array<JSON> = []
    //显示频道列表的tableView
    var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        test1()
    }
}

extension JSViewController49 {
    fileprivate func test1() {
        //获取数据
        DouBanProvider.rx.request(.channels).subscribe { event in
            switch event {
            case let .success(response):
                //数据处理
                let str = String(data: response.data, encoding: String.Encoding.utf8)
                print("返回的数据是：", str ?? "")
            case let .error(error):
                print("数据请求失败!错误原因：", error)
            }
        }.disposed(by: disposeBag)
    }

    fileprivate func test2() {
        //获取数据
        DouBanProvider.rx.request(.channels).subscribe(onSuccess: { response in
            //数据处理
            let str = String(data: response.data, encoding: String.Encoding.utf8)
            print("返回的数据是：", str ?? "")
        }, onError: { error in
            print("数据请求失败!错误原因：", error)
        }).disposed(by: disposeBag)
    }

}
